 auto evbase = event_base_new();
   LibEventHandlerMyError hndl(evbase);


   // 建立连接
   AMQP::TcpConnection connection(&hndl, AMQP::Address(
       "amqp://admin:eyJrZXlJZC...@amqp-xxx.rabbitmq.ap-sh.public.tencenttdmq.com:5672/amqp-xxx|vhost-cpp"));
       // 服务地址格式为  amqp://username:password@host:port/vhost
   // 建立通道
   AMQP::TcpChannel channel(&connection);
   channel.onError([&evbase](const char *message) {
       std::cout << "Channel error: " << message << std::endl;
       event_base_loopbreak(evbase);
   });




// 声明交换机
channel.declareExchange(exchange_name, AMQP::ExchangeType::direct);


// 发送消息到交换机
channel.publish(exchange_name, routing_key, "Hello client this is a info message");


event_base_dispatch(evbase);
event_base_free(evbase);









ConnHandler handler;
// 建立连接
AMQP::TcpConnection connection(handler, AMQP::Address(host, part, AMQP::Login(username, password), vhost));
// 建立通道
AMQP::TcpChannel channel(&connection);
channel.onError([&handler](const char *message) {
        std::cout << "Channel error: " << message << std::endl;
        handler.Stop();
});














// 声明交换机
channel.declareExchange(exchange_name, AMQP::ExchangeType::direct);
// 声明消息队列
channel.declareQueue(queue_name, AMQP::durable);
// 绑定消息队列到交换机
channel.bindQueue(exchange_name, queue_name, routing_key);







// 订阅消息
channel.consume(queue_name)
        .onReceived
        (
        [&channel](const AMQP::Message &msg, uint64_t tag, bool redelivered) {
                // 处理消息
                std::cout << "Received: " << msg.body() << std::endl;
                // 回复ack，  消费失败可回复reject
                channel.ack(tag);
        }
);
handler.Start();














